import 'package:flutter/material.dart';

const CITY_NAMES = {
  '中国': ['北京', '上海', '广州', '深圳', '杭州', '苏州', '成都', '武汉', '郑州'],
  '俄罗斯': ['莫斯科', '斯大林格勒'],
  '美国': ['纽约', '旧金山', '芝加哥', '华盛顿', 'DC']
};

class SearchPage extends StatefulWidget {
  @override
  _SearchPageState createState() => _SearchPageState();
}

class _SearchPageState extends State<SearchPage> {
  @override
  Widget build(BuildContext context) {
    final title = '列表收起';

    return Scaffold(
      backgroundColor: Color(0xfff2f2f2),
      appBar: AppBar(
        title: Text(title),
      ),
      body: Container(
        child: ListView(
          children: _buildList(),
        ),
      ),
    );
  }

  List<Widget> _buildList() {
    List<Widget> widgets = [];
    CITY_NAMES.keys.forEach((key) {
      widgets.add(_item(key, CITY_NAMES[key]));
    });
    return widgets;
  }

  Widget _item(String country, List<String> citys) {
    return ExpansionTile(
      title: Text(
        country,
        style: TextStyle(color: Colors.black54, fontSize: 20),
      ),
      children: citys.map((citySub) => _buildSub(citySub)).toList(),
    );
  }

  Widget _buildSub(String city) {
    return FractionallySizedBox(
      // height: 80,
      widthFactor: 1,
      child: Container(
        height: 50,
        margin: EdgeInsets.only(top: 5),
        decoration: BoxDecoration(color: Colors.pink[100]),
        child: Text(city),
      ),
    );
  }

  cityField(String city) {
    return TextFormField(
      cursorColor: Colors.white,
      decoration: InputDecoration(
        hintText: city,
      ),
    );
  }

  // List<Widget> _buildList() {
  //   return CITY_NAMES.map((city) => _item(city)).toList();
  // }

  // Widget _item(String city) {
  //   return Container(
  //     // height: 80,
  //     width: 160,
  //     margin: EdgeInsets.only(right: 5),
  //     alignment: Alignment.center,
  //     decoration: BoxDecoration(
  //       image: DecorationImage(
  //         image: AssetImage('assets/city/background_beijing.jpg'),
  //         fit: BoxFit.cover,
  //       ),
  //     ),
  //     child: Scaffold(
  //       backgroundColor: Colors.transparent,
  //       body: ListView(
  //         children: <Widget>[
  //           cityField(city),
  //         ],
  //       ),
  //     ),
  //   );
  // }
}
